<style lang="less" scoped>
  @import "../../assets/css/variable.less"; // less变量
  .course_video_cover {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .inner {
      .flex_col();
      align-items: center;
      &.move {
        margin-bottom: 250px;
      }
      img {
        width: 101vw;
        height: 100%;
        position: absolute;
        left: 0%;
        top: 0%;
        &.full {
          height: 101vh;
        }
      }
      .logo {
        position: relative;
        z-index: 1;
        .flex_center();
        i {
          width: 59px;
          height: 59px;
          background: url('../../assets/images/zxjtqh/zxjt_logo.png') center/100% no-repeat;
        }
        span {
          font-size: 28px;
          color: #333;
          margin-left: 10px;
          white-space: nowrap;
        }
      }
      .tip {
        margin-top: 34px;
        font-size: 28px;
        color: #333;
        white-space: nowrap;
        z-index: 1;
      }
      .btn {
        height: 74px;
        background: linear-gradient(270deg, #F7E0C1 0%, #FCF2E2 100%);
        border-radius: 37px;
        border: 2px solid #FFCB9F;
        display: flex;
        padding: 0 46px;
        margin-top: 34px;
        position: relative;
        z-index: 1;
        span {
          margin: auto;
          font-size: 28px;
          color: #F4693F;
          white-space: nowrap;
        }
        .badge {
          background: #E8340A;
          border-radius: 18px;
          padding: 6px 8px;
          position: absolute;
          top: 0;
          right: 0;
          transform: translate(50%, -50%);
          font-size: 20px;
          text-decoration: line-through;
          color: #fff;
        }
      }
    }
  }
</style>

<template>
  <div class="course_video_cover" :class="{move: mode == 2}">
    <div class="inner" :class="{move: mode == 2 || mode == 1 }">
      <img src="../../assets/images/zxjtqh/course_video_full_bg.png" alt="" v-if="mode == 1" :class="{full: mode == 1}">
      <img src="../../assets/images/zxjtqh/course_video_half_bg.png" alt="" v-else>
      <div class="logo"><i></i><span>中信建投</span></div>
      <span class="tip">{{tipText}}</span>
      <div class="btn" @click="handleBuyCourse">
        <span> {{ btnText }}</span>
        <div class="badge" v-if="courseInfo.linePrice && courseInfo.buyPrice && courseInfo.priceType">原价￥{{courseInfo.linePrice}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { subscribeCourse,} from '@/util/api.js'
  export default {
    name: "CourseVideoCover",
    props: {
      courseInfo: {
        type: Object,
        default: {},
      },
      videoInfo:{
        type: Object,
        default: {},
      }
    },
    data() {
      return {
        mode:'',
        tipText:'',
        btnText:'',
      }
    },
    created() {
      let  {videoInfo:{mode}} = this.videoInfo;
      this.mode = mode;
      //priceType //0 免费 1付费
      const  { priceType , buyPrice , shelveType} = this.courseInfo;
      if(shelveType == '2'){
        this.tipText = '课程已结束，不再支持学习';
        this.btnText = '我知道了';
      }else{
        if( priceType ){//付费
          this.tipText = '本课程是付费专享内容';
          if(buyPrice){
            this.btnText = `￥${buyPrice}购买此课程`;
          }else{
            this.btnText = '前往购买';
          }
        }else{//免费
          this.tipText = '若需观看,请先订阅该课程';
          this.btnText = '免费订阅并观看';
        }      
      }
    },
    methods: {
      // 购买订阅课程
     async  handleBuyCourse() {
        if (this.$store.state.isYk) {
          fun.ykDisposeFun();
        }else{
          const  { shelveType , courseId , priceType} = this.courseInfo;
          if(shelveType == 2){
            this.$router.replace(`/${this.$channel}/home`);
            return 
          }
          if(priceType){//付费
            if (window.terminal.isZxjtqhApp) {
              //商城页面
              fun.zxjtqhLinkUrl(`${config.zxjtqhShoppingUrl}?returnUrl=${location.href}&courseId=${courseId}&topmargin=${window.topmargin}`)
            } else {
              // 拉起app/app下载
              window.open('https://app.cfc108.com:7443/download.html');
            }
          }else{
            console.log('免费未购买');
            const { data: { code, data }} = await subscribeCourse(courseId);
            if (code === '000000' && data) {
              fun.toastMessage('订阅成功', 2000);
              this.$emit('formChildMsg', {type: 'subscribeCourseSucess',data: {}});
            } else {
              console.log('订阅接口error');
            }
          }         
        }
      }
    }
  };
</script>